package com.jule.miaozhuapc.service.impl;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ImportResource;
import org.springframework.stereotype.Service;

import com.jule.miaozhuapc.dao.RoomDao;
import com.jule.miaozhuapc.dao.UserDao;
import com.jule.miaozhuapc.domain.WawaRoom;
import com.jule.miaozhuapc.domain.WawaUser;
import com.jule.miaozhuapc.dto.RoomDetail;
import com.jule.miaozhuapc.service.RoomService;

import java.util.List;


@Service
@Transactional
public class RoomServiceImpl implements RoomService{
	@Autowired
	RoomDao roomdao;
	@Autowired
	UserDao userDao;
	@Override
	public List<WawaRoom> findAllRoom() {
		return roomdao.findAllRoom();
	}

	@Override
	public WawaRoom findById(Long id) {
		// TODO Auto-generated method stub
		return roomdao.findById(id);
	}

	@Override
	public RoomDetail findRoomDetailAndUser(Long roomId, Long userId) {
		
		WawaRoom room = roomdao.findById(roomId);
		WawaUser user = userDao.findByUserId(userId);
		
		RoomDetail roomDetail = new RoomDetail();
		if (user != null && room != null) {
			roomDetail.setCoin(user.getCoin());
			roomDetail.setGameTime(room.getGameTime());
			roomDetail.setRoomCoin(room.getCoin());
			roomDetail.setUserId(user.getId());
			roomDetail.setVideoNormal(room.getVideoNormal());
			roomDetail.setVideoRight(room.getVideoRight());
			//roomDetail.setVideoNormal(room.getVideoNormal());
			//roomDetail.setVideoRight(room.getVideoRight());
		}
		return roomDetail;
	}

}
